<?php
require 'conn.php';

$query = "SELECT * FROM advertising";
$result = mysql_query($query);
$num = mysql_num_rows($result);

echo "<table border=1>";
echo "<tr>";
echo "<th>广告图片</th>";
echo "<th>店铺名称</th>";
echo "<th>编辑</th>";
echo "</tr>";

for ($i = 0; $i < $num; $i++)
{
	$row = mysql_fetch_array($result);
	$adId = $row['ad_id'];
	$image = $row['image'];
	$tabbarId = $row['tabbar'];
	$adIndex = $row['ad_index'];
	$shop_id = $row['shop_id'];
	
	echo "<tr>";
	echo "<td colspan='3'>";
	if ($adIndex == 0 )
	{
		if ($tabbarId == 0) {
			echo "最新资讯";	
		}
		elseif ($tabbarId == 1){
			echo "<br/>";
			echo "<br/>";
			echo "最新优惠";
		}
		elseif ($tabbarId == 2){
			echo "<br/>";
			echo "<br/>";
			echo "餐饮娱乐";
		}
		elseif ($tabbarId == 3){
			echo "<br/>";
			echo "<br/>";
			echo "购物丽人";
		}
	}

	echo "</td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<td>";
	echo "<image src=".$image." width='640' height='200'/>";
	echo "</td>";

	$query1 = "SELECT name FROM shop WHERE shop_id=".$shop_id;
	$result1 = mysql_query($query1);
	$row = mysql_fetch_row($result1);
	$shopName = $row[0];
	echo "<td>";
	echo $shopName;
	echo "</td>";
?>	
	<td>
		<form action="updateAdvertising.php" method="post" enctype="multipart/form-data">
			<?php 
				echo "<input name='adId' type='hidden' value=$adId>";
				echo "<input name='image' type='hidden' value=$image>";
			?>
			选择广告关联的店铺:
			<select name="shopId" >
				<option value=""></option>
				<?php 
					if ($tabbarId == 0)
						$query2 = "SELECT shop_id, name FROM shop";
					else 
						$query2 = "SELECT shop_id, name FROM shop WHERE type=".$tabbarId;
					$result2 = mysql_query($query2);
					$num2 = mysql_num_rows($result2);
					for ($j = 0; $j<$num2;$j++)
					{
						$row2 = mysql_fetch_array($result2);	
						$shop_id = $row2['shop_id'];
						$shop_name = $row2['name'];
						echo "<option value=".$shop_id.">".$shop_name."</option>";					
					}
				?>
			</select>
			<br/>
			<br/>
			<input id="file" type="file" name="file"">
			<input name="scan" type="hidden" id="up" value="true">
			<br/>
			<br/>
			<br/>
			<input type="submit" value="修改"/>
		</form>
	</td>
<?php 	
	echo "</tr>";
	
}
echo "</table>";

?>